package com.cyl.manager.yee.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import com.cyl.manager.yee.convert.ComplaintInfoFlatConvert;
import com.cyl.manager.yee.domain.ComplaintInfoFlat;
import com.cyl.manager.yee.pojo.query.ComplaintInfoFlatQuery;
import com.cyl.manager.yee.service.ComplaintInfoFlatService;
import com.cyl.manager.yee.pojo.vo.ComplaintInfoFlatVO;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;

import cn.hutool.core.date.DateUtil;
/**
 * 会员订单投诉Controller
 *
 * @author hxw
 * @date 2025-04-17
 */
@Api(description ="会员订单投诉接口列表")
@RestController
@RequestMapping("/yee/complaintInfoFlat")
public class ComplaintInfoFlatController extends BaseController {
    @Autowired
    private ComplaintInfoFlatService service;
    @Autowired
    private ComplaintInfoFlatConvert convert;

    @ApiOperation("查询会员订单投诉列表")
    @PreAuthorize("@ss.hasPermi('yee:complaintInfoFlat:list')")
    @PostMapping("/list")
    public ResponseEntity<Page<ComplaintInfoFlat>> list(@RequestBody ComplaintInfoFlatQuery query, Pageable page) {
    	Long qrDeptZbjId = SecurityUtils.getDeptZbjId();
        if(qrDeptZbjId!=null) {
        	query.setDeptZbjId(qrDeptZbjId);
        }
        List<ComplaintInfoFlat> list = service.selectList(query, page);
        return ResponseEntity.ok(new PageImpl<>(list, page, ((com.github.pagehelper.Page)list).getTotal()));
    }

    @ApiOperation("导出会员订单投诉列表")
    @PreAuthorize("@ss.hasPermi('yee:complaintInfoFlat:export')")
    @Log(title = "会员订单投诉", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public ResponseEntity<String> export(ComplaintInfoFlatQuery query) {
    	Long qrDeptZbjId = SecurityUtils.getDeptZbjId();
        if(qrDeptZbjId!=null) {
        	query.setDeptZbjId(qrDeptZbjId);
        }
        List<ComplaintInfoFlat> list = service.selectList(query, null);
        ExcelUtil<ComplaintInfoFlatVO> util = new ExcelUtil<>(ComplaintInfoFlatVO.class);
        return ResponseEntity.ok(util.writeExcel(convert.dos2vos(list), "会员订单投诉数据"));
    }

    @ApiOperation("获取会员订单投诉详细信息")
    @PreAuthorize("@ss.hasPermi('yee:complaintInfoFlat:query')")
    @GetMapping(value = "/{id}")
    public ResponseEntity<ComplaintInfoFlat> getInfo(@PathVariable("id") Long id) {
        return ResponseEntity.ok(service.selectById(id));
    }

    
    
    

    @ApiOperation("同步数据")
    @PreAuthorize("@ss.hasPermi('yee:complaintInfoFlat:add')")
    @Log(title = "同步数据", businessType = BusinessType.INSERT)
    @PostMapping
    public ResponseEntity<Integer> add(@RequestBody ComplaintInfoFlat complaintInfoFlat) {
    	String startTime = DateUtil.format(complaintInfoFlat.getComplaintTime(), "yyyy-MM-dd");
    	String endTime = DateUtil.format(complaintInfoFlat.getTradeTime(), "yyyy-MM-dd");
    	Integer page = null;
    	Integer limit = null;
        try {
        	 page = Integer.parseInt(complaintInfoFlat.getCljg()) ;
        	 limit = Integer.parseInt(complaintInfoFlat.getClzt());
		} catch (Exception e) {

		}
        return ResponseEntity.ok(service.loadYeeDate(startTime, endTime, complaintInfoFlat.getMerchantNo(),page,limit));
    }

    
    @ApiOperation("修改会员订单投诉")
    @PreAuthorize("@ss.hasPermi('yee:complaintInfoFlat:edit')")
    @Log(title = "会员订单投诉", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResponseEntity<Integer> edit(@RequestBody ComplaintInfoFlat complaintInfoFlat) {
        return ResponseEntity.ok(service.update(complaintInfoFlat));
    }


}
